﻿using Corina.DataContext.Master;
using Corina.Datamodel.DataObject;
using Corina.Datamodel.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Corina.Webservice.Cydee
{
    /// <summary>
    /// Summary description for Area
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Area : WebserviceBase
    {

        #region Province
        [WebMethod]
        public ResultInfo GetProvinceItems(string key)
        {
            return GetInstance<ProvinceMaster>().GetAllItems(key);
        }

        [WebMethod]
        public ResultInfo UpdateProvince(string account, string password, string name, string english, int id)
        {
            ProvinceInfo entity = new ProvinceInfo() { Name = name, English = english, Id = id };
            return GetInstance<ProvinceMaster>().Update(account, password, entity, Enumerations.EntityOperation.Update);
        }

        [WebMethod]
        public ResultInfo InsertProvince(string account, string password, string name, string english, string code)
        {
            ProvinceInfo entity = new ProvinceInfo() { Name = name, English = english, Code = code };
            return GetInstance<ProvinceMaster>().Update(account, password, entity, Enumerations.EntityOperation.Insert);
        }

        [WebMethod]
        public ResultInfo RemoveProvince(string account, string password, int id)
        {
            ProvinceInfo entity = new ProvinceInfo() { Id = id };
            return GetInstance<ProvinceMaster>().Update(account, password, entity, Enumerations.EntityOperation.Delete);
        }

        [WebMethod]
        public ResultInfo GetNewProvince(string account, string password)
        {
            return GetInstance<ProvinceMaster>().GetNewEntity(account, password);
        }
        #endregion

        #region City
        [WebMethod]
        public ResultInfo GetCityItems(string provinceCode, string key, int index, int size)
        {
            return GetInstance<CityMaster>().GetAllItems(provinceCode, key, index, size);
        }

        [WebMethod]
        public ResultInfo UpdateCity(string account, string password, string name, string english, string postCode, string areaCode, int id)
        {
            CityInfo entity = new CityInfo() { Name = name, English = english, Id = id, AreaCode = areaCode, PostCode = postCode };
            return GetInstance<CityMaster>().Update(account, password, entity, Enumerations.EntityOperation.Update);
        }

        [WebMethod]
        public ResultInfo InsertCity(string account, string password, string name, string english, string postCode, string areaCode, string code)
        {
            CityInfo entity = new CityInfo() { Name = name, English = english, Code = code, PostCode = postCode, AreaCode = areaCode };
            return GetInstance<CityMaster>().Update(account, password, entity, Enumerations.EntityOperation.Insert);
        }

        [WebMethod]
        public ResultInfo RemoveCity(string account, string password, int id)
        {
            CityInfo entity = new CityInfo() { Id = id };
            return GetInstance<CityMaster>().Update(account, password, entity, Enumerations.EntityOperation.Delete);
        }

        [WebMethod]
        public ResultInfo GetNewCity(string account, string password, string provinceCode)
        {
            return GetInstance<CityMaster>().GetNewEntity(account, password, provinceCode);
        }

        [WebMethod]
        public ResultInfo GetCityInfo(string account, string password, int id)
        {
            return GetInstance<CityMaster>().GetCityInfo(account, password, id);
        }
        #endregion
    }
}
